<template>
<div>
  <el-table :data="tableData" border stripe header-cell-class-name="headerBg" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55"></el-table-column>
    <el-table-column prop="id" label="ID" width="80"></el-table-column>
    <el-table-column prop="name" label="文件名称" ></el-table-column>
    <el-table-column prop="type" label="文件类型" width="120"></el-table-column>
    <el-table-column prop="size" label="文件大小(KB)" ></el-table-column>
    <el-table-column prop="url" label="下载链接" ></el-table-column>
    <el-table-column prop="enable" label="启用" ></el-table-column>
    <el-table-column label="操作" width="180px">
      <template slot-scope="scope">
        <el-button type="primary" @click="handleEdit(scope.row)">编辑 <i class="el-icon-edit"></i></el-button>
        <!--              <el-popconfirm-->
        <!--                class="ml-5"-->
        <!--                confirm-button-text='确定'-->
        <!--                cancel-button-text='我再想想'-->
        <!--                icon="el-icon-info"-->
        <!--                icon-color="red"-->
        <!--                title="您确定删除吗？"-->
        <!--                @confirm="del(scope.row.id)"-->
        <!--              >-->
        <!--              <el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>-->
        <!--              </el-popconfirm>-->
        <el-button type="danger" @click="del(scope.row.id)">删除 <i class="el-icon-remove-outline"></i></el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
export default {
  name: "File",
  data(){
    return {
      tableData: [],
    }
  },
  methods: {
    load(){
      this.request.get("/user/page", {
        params:{
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          username: this.username,
          address: this.address
        }}).then(res =>{
        console.log(res)
        this.tableData = res.data
        this.total = res.total
      })
    },
    save(){
      this.request.post("/user/editUser", this.form).then(res => {
        if (res){
          this.$message.success("保存成功")
          this.dialogFormVisible = false
          this.load()
        }else {
          this.$message.error("保存失败")
        }
      })
    },
    handleAdd(){
      this.dialogFormVisible = true
      this.form = {}
    },
    handleEdit(row){
      this.form = Object.assign({},row)
      this.dialogFormVisible = true
    },
    del(id){
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.request.delete("/user/delUser?id=" + id).then(res => {
          if (res){
            this.$message.success("删除成功")
            this.load()
          }else {
            this.$message.error("删除失败")
          }
        })
      });
    },
    handleSelectionChange(val){
      console.log(val)
      this.multipleSelection = val
    },
    deleteBatch(){
      let ids = this.multipleSelection.map(v => v.id) //将对象数组变成纯id数组 [{},{},{}] => [1,2,3]
      this.$confirm('此操作将永久批量删除选中数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.request.delete("/user/delBatch", {data: ids}).then(res => {
          if (res){
            this.$message.success("批量删除成功")
            this.load()
          }else {
            this.$message.error("批量删除失败")
          }
        })
      });
    },
    reset(){
      this.username = ""
      this.address = ""
      this.load()
    },
    handleSizeChange(pageSize){
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum){
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    exp(){
      window.open("http://localhost:8082/user/export")
    },
    handleExcelImportSuccess(){
      this.$message.success("导入成功")
      this.load()
    },
  }
}
</script>

<style scoped>

</style>
